package com.kitwee.serialport.decoder.mitsubishi;


import com.kitwee.serialport.decoder.InstructionDecoder;

/**
 * 三菱FX系统解码器（三菱无顺序协议）
 *
 * @author szhyde
 */
public class FXInstructionDecoder extends InstructionDecoder {


    @Override
    public synchronized Object decode(byte[] source) {
        try {
            byte[] tempByte = new byte[source.length - 4];
            System.arraycopy(source, 1, tempByte, 0, tempByte.length);

            char[] sourceChar = new String(tempByte).toCharArray();

            char[] temp = new char[sourceChar.length];

            int tempIndex = 0;
            for (int i = sourceChar.length - 1; i >= 0; i = i - 2) {
                if (temp.length > (tempIndex) && temp.length > 1) {
                    temp[tempIndex++] = sourceChar[i - 1];
                }
                temp[tempIndex++] = sourceChar[i];
            }
            return byteArray2int(asciiTransformByte(temp));

        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }


}
